package test.hystrix;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

public class ProxyFactory {
	
	public static Object getProxy(@SuppressWarnings("rawtypes") Class clazz) {
		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(clazz);
		enhancer.setCallback(new MethodInterceptor() {
			
			@Override
			public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
				 TestCommand tc = new TestCommand();
				 System.out.println(tc);
				 Object result = tc.execute();
				 return result;
			}
		});
		return enhancer.create();
	}

}
